package com.estar.assistsurvy.adapter;

import java.util.ArrayList;

import com.estar.assistsurvy.R;
import com.estar.assistsurvy.entity.WalletItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class WalletListviewAdapter extends BaseAdapter {

	private ArrayList<WalletItem> list;
	private LayoutInflater inflater;
	
	public WalletListviewAdapter(ArrayList<WalletItem> list, Context context) {
		super();
		this.list = list;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		viewHolder holder;
		if(convertView==null){
			holder=new viewHolder();
			convertView=inflater.inflate(R.layout.listview_wallet, null);
			holder.accountIcon=(ImageView) convertView.findViewById(R.id.accountIcon);
			holder.accountType=(TextView) convertView.findViewById(R.id.accountType);
			holder.accountDetail=(ImageView) convertView.findViewById(R.id.accountDetail);
			holder.accountOfMoney=(TextView) convertView.findViewById(R.id.accountOfMoney);
			convertView.setTag(holder);
		}else{
			holder=(viewHolder) convertView.getTag();
		}
		
		WalletItem item=list.get(position);
		holder.accountDetail.setImageResource(R.drawable.btn_more);
		holder.accountIcon.setImageResource(item.getIcon());
		holder.accountType.setText(item.getType());
		holder.accountOfMoney.setText(item.getDetail());
		
		return convertView;
	}

	private class viewHolder{
		private ImageView accountIcon,accountDetail;
		private TextView accountType,accountOfMoney;
	}

}
